package com.wn.project.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wn.common.PageBean;
import com.wn.entity.Document;
import com.wn.entity.InventoryBookkeeping;
import com.wn.project.mapper.DocumentMapper;
import com.wn.project.service.DocumentService;
import com.wn.utils.CurrentTime;
import com.wn.utils.PageBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: pms
 * @ClassName DocumentServiceImpl
 * @description:
 * @author: LRW
 * @create: 2022-10-25 14:57
 * @Version 1.0
 **/
@Service
public class DocumentServiceImpl implements DocumentService {

    @Autowired
    private DocumentMapper documentMapper;

    @Override
    public void add(Document document) {
        document.setTime(CurrentTime.getCurrentTimeString());
        document.setVersion(1);
        documentMapper.add(document);
    }

    @Override
    public void deleteById(int id){
        documentMapper.deleteById(id);
    }

    @Override
    public PageBean<Document> getByCondition(Document document, int pageSize, int currPage) {
        Page<Document> page = PageHelper.startPage(currPage, pageSize);
        List<Document> list = documentMapper.selectByCondition(document);
        return PageBeanUtil.getPageBean(list, page, currPage, pageSize);
    }

    @Override
    public void update(Document document) {
        document.setVersion(documentMapper.selectById(document.getId()).getVersion() + 1);
        documentMapper.update(document);
    }

    @Override
    public Document getById(int id) {
        return documentMapper.selectById(id);
    }


}
